import { _decorator, Component, Node, Prefab, instantiate, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('FMMN_loginbonusUI')
export class FMMN_loginbonusUI extends Component {
    @property(Prefab)
    private prefabNode: Prefab = null!;

    @property(Node)
    private spawnParent: Node = null!;

    private activeNodes: Node[] = [];
    private maxNodes: number = 10;

    onLoad() {
        this.node.on(Node.EventType.TOUCH_END, this.onButtonClick, this);
    }

    private onButtonClick() {
        if (this.activeNodes.length >= this.maxNodes) {
            this.activeNodes[0].destroy();
            this.activeNodes.shift();
        }

        const newNode = instantiate(this.prefabNode);


        this.spawnParent.addChild(newNode);


        this.activeNodes.push(newNode);

        // 调试输出
        console.log("Node created at:", newNode.position.toString());
    }
}